﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccess;
using System.Data;
using System.Text;
using System.Net.Mail;
using Liguo.AppCode;

namespace Liguo.Store
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //页面加载时显示artDialog
            Response.Write("<head><link rel=\"stylesheet\" href=\"../js/artDialog/skins/simple.css\"></link></head>");
            Response.Write("<head><script src=\"../js/artDialog/artDialog.js\"></script></head>");
            Response.Write("<body><script>art.dialog({time: 2, content: '两秒后关闭'});</script></body>");

            //访问数据库通过调用SqlIt的方法，具体方法见该类
            SqlIt sql = new SqlIt();
            //DataSet类承接查询结果
            DataSet ds = sql.SelectAll("UserInfo");
            //通过DataSet访问查询结果的某个内容
            //使用textbox显示
            text.Text = ds.Tables[0].Rows[0]["UserName"].ToString();
            //大致上就是这个样子
            //有什么不懂大家可以互相讨论  

            Logo.ImageUrl = "../res/logo327x135.png";

            //邮件发送

        }

        private void SendEMail()
        {
            try
            {
                //邮件服务器，比如这个就是新浪邮箱的发件服务器
                SmtpClient client = new SmtpClient("smtp.163.com");
                client.UseDefaultCredentials = false;
                //163的smtp服务默认端口25
                client.Port = 25;
                //"发送邮箱的用户名", "发送邮箱的密码"
                client.Credentials = new System.Net.NetworkCredential("liguoserver", "liguoshe");               
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                MailMessage mail = new MailMessage();
                //"接收邮件的邮箱，就是你要发给谁"
                mail.From = new MailAddress("liguoserver@163.com");
                //"抄送给谁，可以不填"
                mail.To.Add("2430154900@qq.com");
                //邮件标题
                mail.Subject = "请尽快激活！";
                mail.BodyEncoding = System.Text.Encoding.Default;
                //邮件内容

                //mail.HeadersEncoding = Encoding.UTF8;
                //mail.BodyEncoding = Encoding.UTF8;
                //mail.Priority = MailPriority.High;
                mail.IsBodyHtml = true;
                string body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
                body += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">";
                body += "</HEAD><BODY><DIV><FONT face=Arial color=#ff0000 size=2>this is some HTML text";
                body += "</FONT></DIV></BODY></HTML>";

                mail.Body = body;
                //附件之类的吧
                //if (list != null)
                //{
                //    foreach (Attachment item in list)
                //    {
                //        mail.Attachments.Add(item);
                //    }
                //}
                mail.IsBodyHtml = true;
                client.Send(mail);
                Response.Write("<script>alert('发送成功');</script>");
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
        }

        protected void BtSendEMail_Click(object sender, EventArgs e)
        {
            SendEMail();
        }
    }
}